package com.ruoyi.web.controller.warehouseManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StockInTypeManagement;
import com.ruoyi.system.service.IStockInTypeManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库类型设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-30
 */
@Api(tags="入库类型设置")
@RestController
@RequestMapping("/system/stockInTypeManagement")
public class StockInTypeManagementController extends BaseController
{
    @Autowired
    private IStockInTypeManagementService stockInTypeManagementService;

    /**
     * 通过入库类型名称查询入库类型设置列表
     */
    @ApiOperation("通过入库类型名称查询入库类型设置列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String typeName)
    {
        startPage();
        List<StockInTypeManagement> list = stockInTypeManagementService.selectStockInTypeManagementListByName(typeName);
        return getDataTable(list);
    }

    /**
     * 导出入库类型设置列表
     */
    @ApiOperation("导出入库类型设置列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "入库类型设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String typeName)
    {
        List<StockInTypeManagement> list = stockInTypeManagementService.selectStockInTypeManagementListByName(typeName);
        ExcelUtil<StockInTypeManagement> util = new ExcelUtil<StockInTypeManagement>(StockInTypeManagement.class);
        util.exportExcel(response, list, "入库类型设置数据");
    }

    /**
     * 通过id获取入库类型设置详细信息
     */
    @ApiOperation("通过id获取入库类型设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockInTypeManagementService.selectStockInTypeManagementById(id));
    }

    /**
     * 新增入库类型设置
     */
    @ApiOperation("新增入库类型设置")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "入库类型设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockInTypeManagement stockInTypeManagement)
    {
        return toAjax(stockInTypeManagementService.insertStockInTypeManagement(stockInTypeManagement));
    }

    /**
     * 修改入库类型设置
     */
    @ApiOperation("修改入库类型设置")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "入库类型设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockInTypeManagement stockInTypeManagement)
    {
        return toAjax(stockInTypeManagementService.updateStockInTypeManagement(stockInTypeManagement));
    }

    /**
     * 通过id批量删除入库类型设置信息
     */
    @ApiOperation("通过id批量删除入库类型设置信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "入库类型设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockInTypeManagementService.deleteStockInTypeManagementByIds(ids));
    }
}
